from django.shortcuts import render

# Create your views here.
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from av_editor.models import MaterialFile
from av_editor.serializers import MaterialFileSerializer, MakeVideoT1Serializer
from av_editor.tasks import make_video_t1


class MaterialFileViewSet(ModelViewSet):
    queryset = MaterialFile.objects.all()
    serializer_class = MaterialFileSerializer

    @action(methods=["POST"], detail=False, serializer_class=MakeVideoT1Serializer)
    def make_video(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        make_video_t1.delay(serializer.data)
        return Response(serializer.data)

